#include<bits/stdc++.h>
using namespace std;
#define int long long

int a[10005];

signed main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];

	vector<int> b;
	for (int i = 1; i <= n; i++) {
		if (b.empty())
			b.push_back(a[i]);
		else if (a[i] != b.back())
			b.push_back(a[i]);
	}


	int ans = 0;
	for (int i = 1; i < b.size() - 1; i++)
		if (b[i - 1] > b[i] && b[i] < b[i + 1])
			ans++;
	cout << ans;
	return 0;
}
